import { NextRequest, NextResponse } from 'next/server';

// GET /api/health - 健康检查端点
export async function GET(request: NextRequest) {
  try {
    // 简单的健康检查，返回服务状态
    const healthStatus = {
      status: 'ok',
      timestamp: new Date().toISOString(),
      service: 'kason-world',
      version: process.env.npm_package_version || '1.0.0',
      uptime: process.uptime(),
      environment: process.env.NODE_ENV || 'development'
    };

    return NextResponse.json(healthStatus, { status: 200 });
  } catch (error) {
    // 如果出现任何错误，返回服务不可用状态
    const errorStatus = {
      status: 'error',
      timestamp: new Date().toISOString(),
      service: 'kason-world',
      error: error instanceof Error ? error.message : 'Unknown error'
    };

    return NextResponse.json(errorStatus, { status: 503 });
  }
}

// POST /api/health - 也支持POST方法（某些健康检查工具可能使用POST）
export async function POST(request: NextRequest) {
  return GET(request);
}